package se.lth.student.axisandroidcam.client;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import android.content.res.Resources;

public class ClientIn extends Thread{
	private Camera cam;
	private String serverAddress;
	private Socket clientSocket;
	private InputStream in;
	
	public ClientIn(Camera cam, String serverAddress){
		this.cam = cam;
		this.serverAddress = serverAddress;
	}
	
	
	public void run(){
		Toolbox.printDebug("Starting Client In");
		try {
			clientSocket = new Socket(serverAddress, AxisAndroidCamera.PORT+cam.getId());
			in = clientSocket.getInputStream();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		while(true){
			fetchImage();
		}
		
		
	}
	
	
	
	private void fetchImage(){				
		try {
			
			byte[] image = new byte[100000];
			int b = in.read();
			int count = 0;
			if(b < 0){
				Toolbox.printDebug("Image feched with size "+b);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
	
	
	
	
	
	
}

